package com.ruoyi.web.controller.gcgl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ConvertUpMoneyUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DecimalCalculateUtil;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.gcgl.domain.GcFk;
import com.ruoyi.gcgl.domain.GcFkfp;
import com.ruoyi.gcgl.domain.GcFkitem;
import com.ruoyi.gcgl.domain.GcProject;
import com.ruoyi.gcgl.domain.GcSupply;
import com.ruoyi.gcgl.domain.SjContract;
import com.ruoyi.gcgl.domain.SjProcessConfig;
import com.ruoyi.gcgl.domain.SjProjectPeople;
import com.ruoyi.gcgl.mapper.GcSendTipMapper;
import com.ruoyi.gcgl.service.IGcFkService;
import com.ruoyi.gcgl.service.IGcFkfpService;
import com.ruoyi.gcgl.service.IGcFkitemService;
import com.ruoyi.gcgl.service.IGcProjectService;
import com.ruoyi.gcgl.service.IGcSendTipService;
import com.ruoyi.gcgl.service.IGcSupplyService;
import com.ruoyi.gcgl.service.ISjContractService;
import com.ruoyi.gcgl.service.ISjProcessConfigService;
import com.ruoyi.gcgl.service.ISjProjectPeopleService;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysRoleService;
import com.ruoyi.system.service.ISysUserService;

/**
 * 款项支付Controller
 * 
 * @author ruoyi
 * @date 2022-12-06
 */
@Controller
@RequestMapping("/gcgl/fk")
public class GcFkController extends BaseController
{
    private String prefix = "gcgl/fk";

    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private IGcFkService gcFkService;
    @Autowired
    private IGcFkitemService gcFkitemService;
    @Autowired
    private ISjContractService sjContractService;
    @Autowired
    private IGcSupplyService gcSupplyService;
    @Autowired
    private IGcFkfpService gcFkfpService;
    @Autowired
    private IGcSendTipService gcSendTipService;
    @Autowired
    private GcSendTipMapper gcSendTipMapper;
    @Autowired
    private IGcProjectService gcProjectService;
    @Resource
    private RuntimeService runtimeService;
    @Resource
    private TaskService taskService;
    @Autowired
    private ISjProcessConfigService sjProcessConfigService;
    @Autowired
    private ISysDeptService deptService;
    @Autowired
    private ISysRoleService roleService;
    
    final String processCode = "sjfukuangshengqing";
    @Autowired
    private ISjProjectPeopleService sjProjectPeopleService;
    
    @RequiresPermissions("gcgl:fk:view")
    @GetMapping()
    public String fk()
    {
        return prefix + "/fk";
    }

    /**
     * 查询款项支付列表
     */
    @RequiresPermissions("gcgl:fk:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GcFk gcFk)
    {
        startPage();
        gcFk.setDeleteFlag(1);
      //角色数据权限 ==根据用户定义的数据权限查看项目数据
        List<SysRole> roles = getSysUser().getRoles();
        List<Long> roleIds = new ArrayList<Long>();
        for(SysRole obj:roles){
        	roleIds.add(obj.getRoleId());
        }
        
        int count = roleService.selectCountRoleDeptByRoleId(roleIds);
        if(count != 0){
        	//看部门
        	gcFk.setRoleIds(roleIds);
        }else{
        	//看个人
        	if(getSysUser().isShowRoleIds(roleIds)){
        		gcFk.setOwnerId(getUserId());
            }
        }
        //----
        List<GcFk> list = gcFkService.selectGcFkList(gcFk);
        return getDataTable(list);
    }

    /**
     * 导出款项支付列表
     */
    @RequiresPermissions("gcgl:fk:export")
    @Log(title = "款项支付", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GcFk gcFk)
    {
    	gcFk.setDeleteFlag(1);
        if(getSysUser().isShow()){
        gcFk.setCreateUser(getLoginName());
        }
        List<GcFk> list = gcFkService.selectGcFkList(gcFk);
        ExcelUtil<GcFk> util = new ExcelUtil<GcFk>(GcFk.class);
        return util.exportExcel(list, "款项支付数据");
    }

    /**
     * 新增款项支付
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        return prefix + "/add";
    }
    
    /**
     * 新增设备材料合同出入库单
     */
    @GetMapping("/addContract/{contractId}/{type}")
    public String addContract(@PathVariable("contractId") Long contractId, @PathVariable("type") Long type, ModelMap mmap){
    	SjContract sjContract = sjContractService.selectSjContractById(contractId);
        mmap.put("obj", sjContract);
        mmap.put("riq", DateUtils.dateTime(new Date()));
        mmap.put("type", type);
        mmap.put("xmfzr", sjContract.getCreateUser());
        mmap.put("supplyName", sjContract.getCustomerName());
        
        GcFk gcFk = new GcFk();
        gcFk.setDeleteFlag(1);
        gcFk.setProjectNo(sjContract.getOrderNo());
        gcFk.setXmtype(Integer.parseInt(type.toString()));
        gcFk.setCkdw("");//sjContract.getSupplyName()
        List<GcFk> gcfklis = gcFkService.selectGcFkList(gcFk);
        
        double ljzf = 0.0;
        for(GcFk obj:gcfklis){
        	ljzf = DecimalCalculateUtil.add(ljzf, Double.parseDouble(obj.getLjzf().toString()));
        }
        mmap.put("kucljzf", ljzf);
        
        GcFkfp gcFkfp = new GcFkfp();
        gcFkfp.setDeleteFlag(1);
        gcFkfp.setProjectId(sjContract.getId());
        gcFkfp.setGcProjectid(sjContract.getGcProjectId());
        gcFkfp.setCkdw(sjContract.getCustomerName());
        List<GcFkfp> fplis = gcFkfpService.selectGcFkfpList(gcFkfp);
        double fpjine = 0.0;
        for(GcFkfp fp:fplis){
        	fpjine = DecimalCalculateUtil.add(fpjine, Double.parseDouble(fp.getFpjine().toString()));
        }
        mmap.put("fpjine", fpjine);
        mmap.put("fkType", fplis.size()==0?"":fplis.get(0).getFpType());
        
        mmap.put("owner", getLoginName());
    	mmap.put("ownerId", getUserId());
    	mmap.put("deptName", getSysUser().getDept().getDeptName());
    	mmap.put("deptId", getSysUser().getDept().getDeptId());
        
        //下一级审核人
        List<SjProcessConfig> configlis = returnUser(Long.valueOf(sjContract.getDeptId().toString()));
        mmap.put("approveid", configlis.get(0).getLevel1id());
        mmap.put("approvename", configlis.get(0).getLevel1name());
        
      //所属
        SysDept dept = new SysDept();
        dept.setDelFlag("1");
        dept.setParentId(100l);
        List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
        mmap.put("deptlis", deptlis);
        return prefix + "/add";
    }
    
    /**
     * 新增保存款项支付
     */
    @RequiresPermissions("gcgl:fk:add")
    @Log(title = "款项支付", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GcFk gcFk){
    	try {
    		SimpleDateFormat sdy = new SimpleDateFormat("yyyy");
    		SimpleDateFormat sdm = new SimpleDateFormat("MM");
    		int year = Integer.parseInt(sdy.format(new Date()));
    		int month = Integer.parseInt(sdm.format(new Date()));
    		GcFk newObj = new GcFk();
    		newObj.setDeleteFlag(1);
    		newObj.setCreateAt(DateUtils.getFisrtDayOfMonth(year, 1));
    		newObj.setUpdateAt(DateUtils.getLastDayOfMonth(year, 12));
    		List<GcFk> lisCount = gcFkService.selectGcFkList(newObj);
    		
    		String no = String.format("%04d", lisCount.size()+1);
    		gcFk.setOrderNo(year+"-"+no);
    		gcFk.setDeleteFlag(1);
        	gcFk.setStatus(1);
        	gcFk.setRiq(new Date());
        	gcFk.setCreateUser(getLoginName());
        	gcFk.setCreateAt(new Date());
        	gcFk.setUpdateUser(getLoginName());
        	gcFk.setUpdateAt(new Date());
        	
        	GcSupply gcSupply = new GcSupply();
        	gcSupply.setDeleteFlag(1);
        	gcSupply.setName(gcFk.getCkdw());
        	List<GcSupply> slis = gcSupplyService.selectGcSupplyList(gcSupply);
        	if(slis!=null && slis.size()>0){
        		gcFk.setNssbh(slis.get(0).getNssbh());
            	gcFk.setKhyh(slis.get(0).getKhyh());
            	gcFk.setSkzh(slis.get(0).getSkzh());
        	}
        	
        	gcFkService.insertGcFk(gcFk);
	        	
        	double ljzf = 0.0;
        	for(GcFkitem item : gcFk.getItems()){
        		
        		ljzf = DecimalCalculateUtil.add(ljzf, Double.parseDouble(item.getJine().toString()));
        		
        		item.setGcProjectid(gcFk.getGcProjectid());
        		item.setProjectId(gcFk.getProjectId());
        		item.setFkId(gcFk.getId());
        		item.setDeleteFlag(1);
        		item.setCreateUser(getLoginName());
        		item.setCreateAt(new Date());
        		item.setUpdateUser(getLoginName());
        		item.setUpdateAt(new Date());
        		gcFkitemService.insertGcFkitem(item);
        	}
        	
        	gcFk.setLjzf(Double.valueOf(ljzf));
        	gcFkService.updateGcFk4check(gcFk);
        	
		} catch (Exception e) {
			return error(e.getMessage());
		}
    	
        return toAjax(1);
    }

    /**
     * 修改款项支付
     */
    @RequiresPermissions("gcgl:fk:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap){
        GcFk gcFk = gcFkService.selectGcFkById(id);
        if(gcFk.getFap()!=null && !gcFk.getFap().equals("")){
        gcFk.setFap(RuoYiConfig.getOnPath()+gcFk.getFap());
        }
        GcFkitem gcFkitem = new GcFkitem();
        gcFkitem.setFkId(id);
        List<GcFkitem> itemlis = gcFkitemService.selectGcFkitemList(gcFkitem);
        gcFk.setItems(itemlis);
        
        mmap.put("gcFk", gcFk);
        
        GcSupply gcSupply = new GcSupply();
        gcSupply.setDeleteFlag(1);
        List<GcSupply> supplylis = gcSupplyService.selectGcSupplyList(gcSupply);
        mmap.put("supplylis", supplylis);
        
        GcFkfp gcFkfp = new GcFkfp();
        gcFkfp.setDeleteFlag(1);
        gcFkfp.setProjectId(gcFk.getProjectId());
        gcFkfp.setGcProjectid(gcFk.getGcProjectid());
        gcFkfp.setCkdw(gcFk.getCkdw());
        List<GcFkfp> fplis = gcFkfpService.selectGcFkfpList(gcFkfp);
        double fpjine = 0.0;
        for(GcFkfp fp:fplis){
        	fpjine = DecimalCalculateUtil.add(fpjine, Double.parseDouble(fp.getFpjine().toString()));
        }
        mmap.put("fpjine", fpjine);
        
        GcFk gcFk11 = new GcFk();
        gcFk11.setDeleteFlag(1);
        gcFk11.setProjectNo(gcFk.getProjectNo());
        gcFk11.setXmtype(gcFk.getXmtype());
        gcFk11.setCkdw(gcFk.getCkdw());
        List<GcFk> gcfklis = gcFkService.selectGcFkList(gcFk11);
        
        double ljzf = 0.0;
        for(GcFk obj:gcfklis){
        	ljzf = DecimalCalculateUtil.add(ljzf, Double.parseDouble(obj.getLjzf().toString()));
        }
        mmap.put("kucljzf", ljzf);
        
      //所属
        SysDept dept = new SysDept();
        dept.setDelFlag("1");
        dept.setParentId(100l);
        List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
        mmap.put("deptlis", deptlis);
        return prefix + "/edit";
    }
    
    /**
     * 修改款项支付
     */
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap){
        GcFk gcFk = gcFkService.selectGcFkById(id);
        if(gcFk.getFap()!=null && !gcFk.getFap().equals("")){
        gcFk.setFap(RuoYiConfig.getOnPath()+gcFk.getFap());
        }
        GcFkitem gcFkitem = new GcFkitem();
        gcFkitem.setFkId(id);
        List<GcFkitem> itemlis = gcFkitemService.selectGcFkitemList(gcFkitem);
        gcFk.setItems(itemlis);
        
        mmap.put("gcFk", gcFk);
        GcSupply gcSupply = new GcSupply();
        gcSupply.setDeleteFlag(1);
        List<GcSupply> supplylis = gcSupplyService.selectGcSupplyList(gcSupply);
        mmap.put("supplylis", supplylis);
        
        GcFkfp gcFkfp = new GcFkfp();
        gcFkfp.setDeleteFlag(1);
        gcFkfp.setProjectId(gcFk.getProjectId());
        gcFkfp.setGcProjectid(gcFk.getGcProjectid());
        gcFkfp.setCkdw(gcFk.getCkdw());
        List<GcFkfp> fplis = gcFkfpService.selectGcFkfpList(gcFkfp);
        double fpjine = 0.0;
        for(GcFkfp fp:fplis){
        	fpjine = DecimalCalculateUtil.add(fpjine, Double.parseDouble(fp.getFpjine().toString()));
        }
        mmap.put("fpjine", fpjine);
        
        //1.设备材料合同 2.施工安装合同 3.工程其它合同 4.一般性费用 5.其它费用
        if(gcFk.getXmtype()==1){
        	SjContract sjContract = new SjContract();
        	sjContract.setDeleteFlag(1);
//        	sjContract.setGcProjectid(gcFk.getGcProjectid());
        	List<SjContract> sjContractlis = 
        			sjContractService.selectSjContractList(sjContract);
        	
        	for(SjContract sjCobj:sjContractlis){
        		sjCobj.setCreateUser("/gcgl/sbclht/detail/"+sjCobj.getId());
        	}
        	
        	mmap.put("sjContractlis", sjContractlis);
		}
        
      //所属
        SysDept dept = new SysDept();
        dept.setDelFlag("1");
        dept.setParentId(100l);
        List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
        mmap.put("deptlis", deptlis);
        
        return prefix + "/detail";
    }

    /**
     * 修改保存款项支付
     */
    @Log(title = "款项支付", businessType = BusinessType.UPDATE)
    @PostMapping("/editSave")
    @ResponseBody
    public AjaxResult editSave(GcFk gcFk){
    	    	
    	try{
    		gcFkitemService.deleteGcFkitemById(gcFk.getId());
    		
    		double ljzf = 0.0;
    		for(GcFkitem item : gcFk.getItems()){
    			
    			ljzf = DecimalCalculateUtil.add(ljzf, Double.parseDouble(item.getJine().toString()));
    			
        		item.setGcProjectid(gcFk.getGcProjectid());
        		item.setProjectId(gcFk.getProjectId());
        		item.setFkId(gcFk.getId());
        		item.setDeleteFlag(1);
        		item.setCreateUser(getLoginName());
        		item.setCreateAt(new Date());
        		item.setUpdateUser(getLoginName());
        		item.setUpdateAt(new Date());
        		gcFkitemService.insertGcFkitem(item);
        	}
    		
    		gcFk.setLjzf(Double.valueOf(ljzf));
    		
            GcSupply gcSupply = new GcSupply();
        	gcSupply.setDeleteFlag(1);
        	gcSupply.setName(gcFk.getCkdw());
        	List<GcSupply> slis = gcSupplyService.selectGcSupplyList(gcSupply);
        	if(slis!=null && slis.size()>0){
        		gcFk.setNssbh(slis.get(0).getNssbh());
            	gcFk.setKhyh(slis.get(0).getKhyh());
            	gcFk.setSkzh(slis.get(0).getSkzh());
        	}
            
        	gcFk.setZjlsb("");
        	gcFk.setCwsh("");
            gcFkService.updateGcFk4check(gcFk);
        }
        catch (Exception e){
            return error(e.getMessage());
        }
    	
        return toAjax(1);
    }

    /**
     * 删除款项支付
     */
    @RequiresPermissions("gcgl:fk:remove")
    @Log(title = "款项支付", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(gcFkService.deleteGcFkByIds(ids));
    }
    
    //--------工程
    /**
     * 总经理审批
     * @return
     */
    @GetMapping("/gcps")
    public String fkgcps(){
        return prefix + "/fkgcps";
    }
    
    /**
     * 查询设备材料合同出入库单列表
     */
    @PostMapping("/gcpslist")
    @ResponseBody
    public TableDataInfo gcpslist(GcFk gcFk){
        startPage();
        gcFk.setDeleteFlag(1);
        gcFk.setStatus(0);
        List<GcFk> list = gcFkService.selectGcFkList(gcFk);
        return getDataTable(list);
    }
    
    @Log(title = "通过", businessType = BusinessType.UPDATE)
    @PostMapping("/gcyes")
    @ResponseBody
    public AjaxResult gcyes(String ids,String spyj, ModelMap mmap){
    	String[] id = Convert.toStrArray(ids);
    	for(int i=0;i<id.length;i++){
    		GcFk gcFk = gcFkService.selectGcFkById(Long.valueOf(id[i].toString()));
    		if(gcFk!=null){
    			GcFk obj = new GcFk();
    			obj.setId(Long.parseLong(id[i]));
    			obj.setStatus(1);
    			obj.setSqr(getLoginName());
    			obj.setSqrAt(new Date());
    			obj.setSpyj(spyj);
    			gcFkService.updateGcFk(obj);
    			
    			GcFk l_obj = gcFkService.selectGcFkById(Long.parseLong(id[i]));
    			
    		}
    	}
    	
    	return toAjax(1);
    }
    
    @Log(title = "不通过", businessType = BusinessType.UPDATE)
    @PostMapping("/gcno")
    @ResponseBody
    public AjaxResult gcno(String ids,String spyj, ModelMap mmap){
    	String[] id = Convert.toStrArray(ids);
    	for(int i=0;i<id.length;i++){
    		GcFk gcFk = gcFkService.selectGcFkById(Long.valueOf(id[i].toString()));
    		if(gcFk!=null){
    			GcFk obj = new GcFk();
    			obj.setId(Long.parseLong(id[i]));
    			obj.setStatus(2);
    			obj.setSqr(getLoginName());
    			obj.setSqrAt(new Date());
    			obj.setSpyj(spyj);
    			gcFkService.updateGcFk(obj);
    			
    			GcFk l_obj = gcFkService.selectGcFkById(Long.parseLong(id[i]));
    		}
    	}
    	
    	return toAjax(1);
    }
    
    /**
     * 总经理审批
     * @return
     */
    @GetMapping("/ps")
    public String fkps(){
        return prefix + "/fkps";
    }
    
    /**
     * 查询设备材料合同出入库单列表
     */
    @PostMapping("/pslist")
    @ResponseBody
    public TableDataInfo pslist(GcFk gcFk){
        startPage();
        gcFk.setDeleteFlag(1);
        gcFk.setStatus(3);
        List<GcFk> list = gcFkService.selectGcFkList(gcFk);
        return getDataTable(list);
    }
    
    @Log(title = "通过", businessType = BusinessType.UPDATE)
    @PostMapping("/yes")
    @ResponseBody
    public AjaxResult yes(String ids,String spyj, ModelMap mmap){
    	String[] id = Convert.toStrArray(ids);
    	for(int i=0;i<id.length;i++){
    		GcFk gcFk = gcFkService.selectGcFkById(Long.valueOf(id[i].toString()));
    		if(gcFk!=null){
    			GcFk obj = new GcFk();
    			obj.setId(Long.parseLong(id[i]));
    			obj.setStatus(5);
    			obj.setZjlsb(getLoginName());
    			obj.setZjlsbAt(new Date());
    			obj.setSpyj(spyj);
    			gcFkService.updateGcFk(obj);
    			
    			GcFk l_obj = gcFkService.selectGcFkById(Long.parseLong(id[i]));
    		}
    	}
    	
    	return toAjax(1);
    }
    
    @Log(title = "不通过", businessType = BusinessType.UPDATE)
    @PostMapping("/no")
    @ResponseBody
    public AjaxResult no(String ids,String spyj, ModelMap mmap){
    	String[] id = Convert.toStrArray(ids);
    	for(int i=0;i<id.length;i++){
    		GcFk gcFk = gcFkService.selectGcFkById(Long.valueOf(id[i].toString()));
    		if(gcFk!=null){
    			GcFk obj = new GcFk();
    			obj.setId(Long.parseLong(id[i]));
    			obj.setStatus(6);
    			obj.setZjlsb(getLoginName());
    			obj.setZjlsbAt(new Date());
    			obj.setSpyj(spyj);
    			gcFkService.updateGcFk(obj);
    			
    			GcFk l_obj = gcFkService.selectGcFkById(Long.parseLong(id[i]));
    		}
    	}
    	
    	return toAjax(1);
    }
    
    //会计审核
    @GetMapping("/fkhjps")
    public String fkhjps(){
        return prefix + "/fkhjps";
    }
    
    /**
     * 查询设备材料合同出入库单列表
     */
    @PostMapping("/hjpslist")
    @ResponseBody
    public TableDataInfo hjpslist(GcFk gcFk)
    {
    	startPage();
        gcFk.setDeleteFlag(1);
        String[] statuslis = new String[]{"1","3","5"};
        gcFk.setStatuslis(statuslis);
        List<GcFk> list = gcFkService.selectGcFkList(gcFk);
        return getDataTable(list);
    }
    
    @Log(title = "通过", businessType = BusinessType.UPDATE)
    @PostMapping("/hjpsyes")
    @ResponseBody
    public AjaxResult hjpsyes(String ids,String spyj, ModelMap mmap){
    	String[] id = Convert.toStrArray(ids);
    	for(int i=0;i<id.length;i++){
    		GcFk gcFk = gcFkService.selectGcFkById(Long.valueOf(id[i].toString()));
    		if(gcFk!=null){
    			GcFk obj = new GcFk();
    			obj.setId(Long.parseLong(id[i]));
    			obj.setStatus(3);
    			obj.setCwsh(getLoginName());
    			obj.setCwshAt(new Date());
    			obj.setSpyj(spyj);
    			gcFkService.updateGcFk(obj);
    			
    			GcFk l_obj = gcFkService.selectGcFkById(Long.parseLong(id[i]));
    		}
    	}
    	
    	return toAjax(1);
    }
    
    @Log(title = "不通过", businessType = BusinessType.UPDATE)
    @PostMapping("/hjpsno")
    @ResponseBody
    public AjaxResult hjpsno(String ids,String spyj, ModelMap mmap){
    	String[] id = Convert.toStrArray(ids);
    	for(int i=0;i<id.length;i++){
    		GcFk gcFk = gcFkService.selectGcFkById(Long.valueOf(id[i].toString()));
    		if(gcFk!=null){
    			GcFk obj = new GcFk();
    			obj.setId(Long.parseLong(id[i]));
    			obj.setStatus(4);
    			obj.setCwsh(getLoginName());
    			obj.setCwshAt(new Date());
    			obj.setSpyj(spyj);
    			gcFkService.updateGcFk(obj);
    			
    			GcFk l_obj = gcFkService.selectGcFkById(Long.parseLong(id[i]));
    		}
    	}
    	return toAjax(1);
    }
    
    @GetMapping("/fksqdprint/{id}")
    public String fksqdprint(@PathVariable("id") Long id, ModelMap mmap){
    	GcFk obj = gcFkService.selectGcFkById(id);
    	
    	if(obj.getAuthority()==null || obj.getAuthority().toString().equals("")){
    		obj.setAuthorityName("");
    	}else{
    		SysDept dept = deptService.selectDeptById(Long.parseLong(obj.getAuthority().toString()));
        	obj.setAuthorityName(dept.getDeptName());
    	}
        
    	double ljzfLast =0.0;
    	GcFkitem items = new GcFkitem();
        items.setFkId(id);
        List<GcFkitem> itemlis= gcFkitemService.selectGcFkitemList(items);
        
        if(itemlis!=null && itemlis.size()<3){
        	
        	for(GcFkitem item:itemlis){
        		ljzfLast = DecimalCalculateUtil.add(ljzfLast, 
        				Double.parseDouble(item.getJine().toString()));
            }
        	
        	for(int i=itemlis.size();i<3;i++){
        		GcFkitem itemobj = new GcFkitem();
        		itemobj.setXuh(i);
            	itemlis.add(itemobj);
        	}
        	
        	obj.setItems(itemlis);
        }
//        double ljzf = DecimalCalculateUtil.add(ljzfLast, Double.parseDouble(obj.getLjzf().toString()));
//        obj.setLjzf(Double.valueOf(ljzfLast));
        
        GcFk gcFk11 = new GcFk();
        gcFk11.setDeleteFlag(1);
        gcFk11.setProjectNo(obj.getProjectNo());
        gcFk11.setXmtype(obj.getXmtype());
        gcFk11.setCkdw(obj.getCkdw());
        List<GcFk> gcfklis = gcFkService.selectGcFkList(gcFk11);
        
        double ljzf = 0.0;
        for(GcFk gcFk22:gcfklis){
        	ljzf = DecimalCalculateUtil.add(ljzf, Double.parseDouble(gcFk22.getLjzf().toString()));
        }
        mmap.put("kucljzf", ljzf);
        
        Double h_zbs = DecimalCalculateUtil.div(ljzf, Double.parseDouble(obj.getHtzje().toString()), 4);
    	obj.setZbs(DecimalCalculateUtil.mul(h_zbs, 100)+"%");
        mmap.put("obj", obj);
        mmap.put("riq", DateUtils.dateTime(obj.getRiq()));
        mmap.put("ljzfdx", ConvertUpMoneyUtil.toChinese(obj.getLjzf().toString()));
        return prefix + "/fksqdprint";
    }
    
    @GetMapping("/fksqdgcsp/{id}")
    public String fksqdgcsp(@PathVariable("id") Long id, ModelMap mmap){
    	GcFk obj = gcFkService.selectGcFkById(id);
        
    	double ljzfLast =0.0;
    	GcFkitem items = new GcFkitem();
        items.setFkId(id);
        List<GcFkitem> itemlis= gcFkitemService.selectGcFkitemList(items);
        
        if(itemlis!=null && itemlis.size()<3){
        	
        	for(GcFkitem item:itemlis){
        		ljzfLast = DecimalCalculateUtil.add(ljzfLast, 
        				Double.parseDouble(item.getJine().toString()));
            }
        	
        	for(int i=itemlis.size();i<3;i++){
        		GcFkitem itemobj = new GcFkitem();
        		itemobj.setXuh(i);
            	itemlis.add(itemobj);
        	}
        	
        	obj.setItems(itemlis);
        }
        
        GcFk gcFk11 = new GcFk();
        gcFk11.setDeleteFlag(1);
        gcFk11.setProjectNo(obj.getProjectNo());
        gcFk11.setXmtype(obj.getXmtype());
        gcFk11.setCkdw(obj.getCkdw());
        List<GcFk> gcfklis = gcFkService.selectGcFkList(gcFk11);
        
        double ljzf = 0.0;
        for(GcFk gcFk22:gcfklis){
        	ljzf = DecimalCalculateUtil.add(ljzf, Double.parseDouble(gcFk22.getLjzf().toString()));
        }
        mmap.put("kucljzf", ljzf);
        
        Double h_zbs = DecimalCalculateUtil.div(ljzf, Double.parseDouble(obj.getHtzje().toString()), 4);
    	obj.setZbs(DecimalCalculateUtil.mul(h_zbs, 100)+"%");
        mmap.put("obj", obj);
        mmap.put("riq", DateUtils.dateTime(obj.getRiq()));
        mmap.put("ljzfdx", ConvertUpMoneyUtil.toChinese(obj.getLjzf().toString()));
        return prefix + "/fksqdgcsp";
    }
    
    @GetMapping("/fksqdzjlsp/{id}")
    public String fksqdzjlsp(@PathVariable("id") Long id, ModelMap mmap){
    	GcFk obj = gcFkService.selectGcFkById(id);
        
    	double ljzfLast =0.0;
    	GcFkitem items = new GcFkitem();
        items.setFkId(id);
        List<GcFkitem> itemlis= gcFkitemService.selectGcFkitemList(items);
        
        if(itemlis!=null && itemlis.size()<3){
        	
        	for(GcFkitem item:itemlis){
        		ljzfLast = DecimalCalculateUtil.add(ljzfLast, 
        				Double.parseDouble(item.getJine().toString()));
            }
        	
        	for(int i=itemlis.size();i<3;i++){
        		GcFkitem itemobj = new GcFkitem();
        		itemobj.setXuh(i);
            	itemlis.add(itemobj);
        	}
        	
        	obj.setItems(itemlis);
        }
//        double ljzf = DecimalCalculateUtil.add(ljzfLast, Double.parseDouble(obj.getLjzf().toString()));
//        obj.setLjzf(Double.valueOf(ljzfLast));
        
        GcFk gcFk11 = new GcFk();
        gcFk11.setDeleteFlag(1);
        gcFk11.setProjectNo(obj.getProjectNo());
        gcFk11.setXmtype(obj.getXmtype());
        gcFk11.setCkdw(obj.getCkdw());
        List<GcFk> gcfklis = gcFkService.selectGcFkList(gcFk11);
        
        double ljzf = 0.0;
        for(GcFk gcFk22:gcfklis){
        	ljzf = DecimalCalculateUtil.add(ljzf, Double.parseDouble(gcFk22.getLjzf().toString()));
        }
        mmap.put("kucljzf", ljzf);
        
        Double h_zbs = DecimalCalculateUtil.div(ljzf, Double.parseDouble(obj.getHtzje().toString()), 4);
    	obj.setZbs(DecimalCalculateUtil.mul(h_zbs, 100)+"%");
        mmap.put("obj", obj);
        mmap.put("riq", DateUtils.dateTime(obj.getRiq()));
        mmap.put("ljzfdx", ConvertUpMoneyUtil.toChinese(obj.getLjzf().toString()));
        return prefix + "/fksqdzjlsp";
    }
    
    @GetMapping("/fksqdhjsp/{id}")
    public String fksqdhjsp(@PathVariable("id") Long id, ModelMap mmap){
    	GcFk obj = gcFkService.selectGcFkById(id);
        
    	double ljzfLast =0.0;
    	GcFkitem items = new GcFkitem();
        items.setFkId(id);
        List<GcFkitem> itemlis= gcFkitemService.selectGcFkitemList(items);
        
        if(itemlis!=null && itemlis.size()<3){
        	
        	for(GcFkitem item:itemlis){
        		ljzfLast = DecimalCalculateUtil.add(ljzfLast, 
        				Double.parseDouble(item.getJine().toString()));
            }
        	
        	for(int i=itemlis.size();i<3;i++){
        		GcFkitem itemobj = new GcFkitem();
        		itemobj.setXuh(i);
            	itemlis.add(itemobj);
        	}
        	
        	obj.setItems(itemlis);
        }
//        double ljzf = DecimalCalculateUtil.add(ljzfLast, Double.parseDouble(obj.getLjzf().toString()));
//        obj.setLjzf(Double.valueOf(ljzfLast));
        
        GcFk gcFk11 = new GcFk();
        gcFk11.setDeleteFlag(1);
        gcFk11.setProjectNo(obj.getProjectNo());
        gcFk11.setXmtype(obj.getXmtype());
        gcFk11.setCkdw(obj.getCkdw());
        List<GcFk> gcfklis = gcFkService.selectGcFkList(gcFk11);
        
        double ljzf = 0.0;
        for(GcFk gcFk22:gcfklis){
        	ljzf = DecimalCalculateUtil.add(ljzf, Double.parseDouble(gcFk22.getLjzf().toString()));
        }
        mmap.put("kucljzf", ljzf);
        
        Double h_zbs = DecimalCalculateUtil.div(ljzf, Double.parseDouble(obj.getHtzje().toString()), 4);
    	obj.setZbs(DecimalCalculateUtil.mul(h_zbs, 100)+"%");
        mmap.put("obj", obj);
        mmap.put("riq", DateUtils.dateTime(obj.getRiq()));
        mmap.put("ljzfdx", ConvertUpMoneyUtil.toChinese(obj.getLjzf().toString()));
        return prefix + "/fksqdhjsp";
    }
    
    @GetMapping("/p4fk/{id}")
    public String p4fk(ModelMap mmap,@PathVariable("id") Long id){
    	GcProject po = gcProjectService.selectGcProjectById(id);
    	mmap.put("gcProject", po);
    	
    	//判断是成员，还是管理员
    	List<SysRole> roles = getSysUser().getRoles();
        List<Long> roleIds = new ArrayList<Long>();
        for(SysRole obj:roles){
        	roleIds.add(obj.getRoleId());
        }
        
    	//看个人
        int flag = 0;//成员
    	if(getSysUser().isShowRoleIds(roleIds)){
    		SjProjectPeople sjProjectPeople = new SjProjectPeople();
            sjProjectPeople.setDeleteFlag(1);
            sjProjectPeople.setGcProjectid(id);
            sjProjectPeople.setCode(getUserId().toString());
            List<SjProjectPeople> peoplelis = sjProjectPeopleService.selectSjProjectPeopleList(sjProjectPeople);
            if(peoplelis!=null && peoplelis.size()>0){
            	for(SjProjectPeople po1:peoplelis){
                	if(po1.getpId()==0l){
                		flag = 1;//领导
                		break;
                	}
                }
            }
        }else{
        	flag = 1;//领导
        }
        mmap.put("flag", flag);
    	return "sj/project/projectDetailFk";
    }

    /**
     * 查询款项支付列表
     */
    @PostMapping("/p4list")
    @ResponseBody
    public TableDataInfo p4list(GcFk gcFk){
        startPage();
        gcFk.setDeleteFlag(1);
      //角色数据权限 ==根据用户定义的数据权限查看项目数据
        List<SysRole> roles = getSysUser().getRoles();
        List<Long> roleIds = new ArrayList<Long>();
        for(SysRole obj:roles){
        	roleIds.add(obj.getRoleId());
        }
        
        int count = roleService.selectCountRoleDeptByRoleId(roleIds);
        if(count != 0){
        	//看部门
        	gcFk.setRoleIds(roleIds);
        }else{
        	//看个人
        	if(getSysUser().isShowRoleIds(roleIds)){
        		gcFk.setOwner(getLoginName());
            }
        }
        //----
        List<GcFk> list = gcFkService.selectGcFkList(gcFk);
        return getDataTable(list);
    }
    
    //---------------------审批方法
    //申请人部门PID
    private List<SjProcessConfig> returnUser(Long deptId){
    	SysDept dept = deptService.selectDeptById(deptId);
    	SjProcessConfig sjProcessConfig = new SjProcessConfig();
        sjProcessConfig.setDeleteFlag(1);
        sjProcessConfig.setCode(processCode);
        sjProcessConfig.setDeptId(dept.getParentId());
        List<SjProcessConfig> configlis = sjProcessConfigService.selectSjProcessConfigList(sjProcessConfig);
		
        if(configlis==null || configlis.size()==0){
        	SjProcessConfig sjProcessConfig1 = new SjProcessConfig();
        	sjProcessConfig1.setDeleteFlag(1);
        	sjProcessConfig1.setCode("morenliucheng");
            List<SjProcessConfig> configlis1 = sjProcessConfigService.selectSjProcessConfigList(sjProcessConfig1);
            return configlis1;
        }
        return configlis;
    }
    
    /**
     * 修改保存项目立项
     */
    @Log(title = "商机立项", businessType = BusinessType.UPDATE)
    @PostMapping("/edit4check")
    @ResponseBody
    public AjaxResult edit4check(GcFk gcFk){
    	try{
    		gcFkitemService.deleteGcFkitemById(gcFk.getId());
    		
    		double ljzf = 0.0;
    		for(GcFkitem item : gcFk.getItems()){
    			
    			ljzf = DecimalCalculateUtil.add(ljzf, Double.parseDouble(item.getJine().toString()));
    			
        		item.setGcProjectid(gcFk.getGcProjectid());
        		item.setProjectId(gcFk.getProjectId());
        		item.setFkId(gcFk.getId());
        		item.setDeleteFlag(1);
        		item.setCreateUser(getLoginName());
        		item.setCreateAt(new Date());
        		item.setUpdateUser(getLoginName());
        		item.setUpdateAt(new Date());
        		gcFkitemService.insertGcFkitem(item);
        	}
    		
    		gcFk.setLjzf(Double.valueOf(ljzf));
    		
            GcSupply gcSupply = new GcSupply();
        	gcSupply.setDeleteFlag(1);
        	gcSupply.setName(gcFk.getCkdw());
        	List<GcSupply> slis = gcSupplyService.selectGcSupplyList(gcSupply);
        	if(slis!=null && slis.size()>0){
        		gcFk.setNssbh(slis.get(0).getNssbh());
            	gcFk.setKhyh(slis.get(0).getKhyh());
            	gcFk.setSkzh(slis.get(0).getSkzh());
        	}
            
        	gcFk.setZjlsb("");
        	gcFk.setCwsh("");
        	gcFkService.updateGcFk4check(gcFk);
        }
        catch (Exception e){
            return error(e.getMessage());
        }
        return toAjax(1);
    }
    
    /**
     * level1
     * @return
     */
    @GetMapping("/level1")
    public String level1(String taskid, ModelMap mmap){
        Task t = taskService.createTaskQuery().taskId(taskid).singleResult();
        String processId = t.getProcessInstanceId();
        ProcessInstance p = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
        if (p != null) {
        	GcFk obj = gcFkService.selectGcFkById(Long.parseLong(p.getBusinessKey().toString()));
        	if(obj.getFap()!=null && !obj.getFap().equals("")){
        		obj.setFap(RuoYiConfig.getOnPath()+obj.getFap());
            }
            GcFkitem gcFkitem = new GcFkitem();
            gcFkitem.setFkId(obj.getId());
            List<GcFkitem> itemlis = gcFkitemService.selectGcFkitemList(gcFkitem);
            obj.setItems(itemlis);
        	mmap.put("obj", obj);
        	
        	GcSupply gcSupply = new GcSupply();
            gcSupply.setDeleteFlag(1);
            List<GcSupply> supplylis = gcSupplyService.selectGcSupplyList(gcSupply);
            mmap.put("supplylis", supplylis);
            
            GcFkfp gcFkfp = new GcFkfp();
            gcFkfp.setDeleteFlag(1);
            gcFkfp.setProjectId(obj.getProjectId());
            gcFkfp.setGcProjectid(obj.getGcProjectid());
            gcFkfp.setCkdw(obj.getCkdw());
            List<GcFkfp> fplis = gcFkfpService.selectGcFkfpList(gcFkfp);
            double fpjine = 0.0;
            for(GcFkfp fp:fplis){
            	fpjine = DecimalCalculateUtil.add(fpjine, Double.parseDouble(fp.getFpjine().toString()));
            }
            mmap.put("fpjine", fpjine);
            
            GcFk gcFk11 = new GcFk();
            gcFk11.setDeleteFlag(1);
            gcFk11.setProjectNo(obj.getProjectNo());
            gcFk11.setXmtype(obj.getXmtype());
            gcFk11.setCkdw(obj.getCkdw());
            List<GcFk> gcfklis = gcFkService.selectGcFkList(gcFk11);
            
            double ljzf = 0.0;
            for(GcFk obj1:gcfklis){
            	ljzf = DecimalCalculateUtil.add(ljzf, Double.parseDouble(obj1.getLjzf().toString()));
            }
            mmap.put("kucljzf", ljzf);
        	
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            mmap.put("taskid", taskid);
            
            //下一级审核人
            mmap.put("approveid", obj.getHjId());
            mmap.put("approvename", obj.getHj());
            
          //所属
            SysDept dept = new SysDept();
            dept.setDelFlag("1");
            dept.setParentId(100l);
            List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
            mmap.put("deptlis", deptlis);
        }
        
        return prefix + "/level1check";
    }
    
    /**
     * level2
     * @return
     */
    @GetMapping("/level2")
    public String level2(String taskid, ModelMap mmap){
        Task t = taskService.createTaskQuery().taskId(taskid).singleResult();
        String processId = t.getProcessInstanceId();
        ProcessInstance p = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
        if (p != null) {
        	GcFk obj = gcFkService.selectGcFkById(Long.parseLong(p.getBusinessKey().toString()));
        	if(obj.getFap()!=null && !obj.getFap().equals("")){
        		obj.setFap(RuoYiConfig.getOnPath()+obj.getFap());
            }
            GcFkitem gcFkitem = new GcFkitem();
            gcFkitem.setFkId(obj.getId());
            List<GcFkitem> itemlis = gcFkitemService.selectGcFkitemList(gcFkitem);
            obj.setItems(itemlis);
        	mmap.put("obj", obj);
        	
        	GcSupply gcSupply = new GcSupply();
            gcSupply.setDeleteFlag(1);
            List<GcSupply> supplylis = gcSupplyService.selectGcSupplyList(gcSupply);
            mmap.put("supplylis", supplylis);
            
            GcFkfp gcFkfp = new GcFkfp();
            gcFkfp.setDeleteFlag(1);
            gcFkfp.setProjectId(obj.getProjectId());
            gcFkfp.setGcProjectid(obj.getGcProjectid());
            gcFkfp.setCkdw(obj.getCkdw());
            List<GcFkfp> fplis = gcFkfpService.selectGcFkfpList(gcFkfp);
            double fpjine = 0.0;
            for(GcFkfp fp:fplis){
            	fpjine = DecimalCalculateUtil.add(fpjine, Double.parseDouble(fp.getFpjine().toString()));
            }
            mmap.put("fpjine", fpjine);
            
            GcFk gcFk11 = new GcFk();
            gcFk11.setDeleteFlag(1);
            gcFk11.setProjectNo(obj.getProjectNo());
            gcFk11.setXmtype(obj.getXmtype());
            gcFk11.setCkdw(obj.getCkdw());
            List<GcFk> gcfklis = gcFkService.selectGcFkList(gcFk11);
            
            double ljzf = 0.0;
            for(GcFk obj1:gcfklis){
            	ljzf = DecimalCalculateUtil.add(ljzf, Double.parseDouble(obj1.getLjzf().toString()));
            }
            mmap.put("kucljzf", ljzf);
        	
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            mmap.put("taskid", taskid);
            
            //下一级审核人
            mmap.put("approveid", obj.getFzjl1Id());
            mmap.put("approvename", obj.getFzjl1());
            
          //所属
            SysDept dept = new SysDept();
            dept.setDelFlag("1");
            dept.setParentId(100l);
            List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
            mmap.put("deptlis", deptlis);
        }
        
        return prefix + "/level2check";
    }
    
    /**
     * level3
     * @return
     */
    @GetMapping("/level3")
    public String level3(String taskid, ModelMap mmap){
        Task t = taskService.createTaskQuery().taskId(taskid).singleResult();
        String processId = t.getProcessInstanceId();
        ProcessInstance p = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
        if (p != null) {
        	GcFk obj = gcFkService.selectGcFkById(Long.parseLong(p.getBusinessKey().toString()));
        	if(obj.getFap()!=null && !obj.getFap().equals("")){
        		obj.setFap(RuoYiConfig.getOnPath()+obj.getFap());
            }
            GcFkitem gcFkitem = new GcFkitem();
            gcFkitem.setFkId(obj.getId());
            List<GcFkitem> itemlis = gcFkitemService.selectGcFkitemList(gcFkitem);
            obj.setItems(itemlis);
        	mmap.put("obj", obj);
        	
        	GcSupply gcSupply = new GcSupply();
            gcSupply.setDeleteFlag(1);
            List<GcSupply> supplylis = gcSupplyService.selectGcSupplyList(gcSupply);
            mmap.put("supplylis", supplylis);
            
            GcFkfp gcFkfp = new GcFkfp();
            gcFkfp.setDeleteFlag(1);
            gcFkfp.setProjectId(obj.getProjectId());
            gcFkfp.setGcProjectid(obj.getGcProjectid());
            gcFkfp.setCkdw(obj.getCkdw());
            List<GcFkfp> fplis = gcFkfpService.selectGcFkfpList(gcFkfp);
            double fpjine = 0.0;
            for(GcFkfp fp:fplis){
            	fpjine = DecimalCalculateUtil.add(fpjine, Double.parseDouble(fp.getFpjine().toString()));
            }
            mmap.put("fpjine", fpjine);
            
            GcFk gcFk11 = new GcFk();
            gcFk11.setDeleteFlag(1);
            gcFk11.setProjectNo(obj.getProjectNo());
            gcFk11.setXmtype(obj.getXmtype());
            gcFk11.setCkdw(obj.getCkdw());
            List<GcFk> gcfklis = gcFkService.selectGcFkList(gcFk11);
            
            double ljzf = 0.0;
            for(GcFk obj1:gcfklis){
            	ljzf = DecimalCalculateUtil.add(ljzf, Double.parseDouble(obj1.getLjzf().toString()));
            }
            mmap.put("kucljzf", ljzf);
        	
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            mmap.put("taskid", taskid);
            
            //下一级审核人
            mmap.put("approveid", obj.getFzjl2Id());
            mmap.put("approvename", obj.getFzjl2());
            
          //所属
            SysDept dept = new SysDept();
            dept.setDelFlag("1");
            dept.setParentId(100l);
            List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
            mmap.put("deptlis", deptlis);
        }
        
        return prefix + "/level3check";
    }
    
    /**
     * level1
     * @return
     */
    @GetMapping("/level4")
    public String level4(String taskid, ModelMap mmap){
        Task t = taskService.createTaskQuery().taskId(taskid).singleResult();
        String processId = t.getProcessInstanceId();
        ProcessInstance p = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
        if (p != null) {
        	GcFk obj = gcFkService.selectGcFkById(Long.parseLong(p.getBusinessKey().toString()));
        	if(obj.getFap()!=null && !obj.getFap().equals("")){
        		obj.setFap(RuoYiConfig.getOnPath()+obj.getFap());
            }
            GcFkitem gcFkitem = new GcFkitem();
            gcFkitem.setFkId(obj.getId());
            List<GcFkitem> itemlis = gcFkitemService.selectGcFkitemList(gcFkitem);
            obj.setItems(itemlis);
        	mmap.put("obj", obj);
        	
        	GcSupply gcSupply = new GcSupply();
            gcSupply.setDeleteFlag(1);
            List<GcSupply> supplylis = gcSupplyService.selectGcSupplyList(gcSupply);
            mmap.put("supplylis", supplylis);
            
            GcFkfp gcFkfp = new GcFkfp();
            gcFkfp.setDeleteFlag(1);
            gcFkfp.setProjectId(obj.getProjectId());
            gcFkfp.setGcProjectid(obj.getGcProjectid());
            gcFkfp.setCkdw(obj.getCkdw());
            List<GcFkfp> fplis = gcFkfpService.selectGcFkfpList(gcFkfp);
            double fpjine = 0.0;
            for(GcFkfp fp:fplis){
            	fpjine = DecimalCalculateUtil.add(fpjine, Double.parseDouble(fp.getFpjine().toString()));
            }
            mmap.put("fpjine", fpjine);
            
            GcFk gcFk11 = new GcFk();
            gcFk11.setDeleteFlag(1);
            gcFk11.setProjectNo(obj.getProjectNo());
            gcFk11.setXmtype(obj.getXmtype());
            gcFk11.setCkdw(obj.getCkdw());
            List<GcFk> gcfklis = gcFkService.selectGcFkList(gcFk11);
            
            double ljzf = 0.0;
            for(GcFk obj1:gcfklis){
            	ljzf = DecimalCalculateUtil.add(ljzf, Double.parseDouble(obj1.getLjzf().toString()));
            }
            mmap.put("kucljzf", ljzf);
        	
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            mmap.put("taskid", taskid);
            
            //下一级审核人
            mmap.put("approveid", obj.getFzjl3Id());
            mmap.put("approvename", obj.getFzjl3());
            
          //所属
            SysDept dept = new SysDept();
            dept.setDelFlag("1");
            dept.setParentId(100l);
            List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
            mmap.put("deptlis", deptlis);
        }
        
        return prefix + "/level4check";
    }
    
    /**
     * level1
     * @return
     */
    @GetMapping("/level5")
    public String level5(String taskid, ModelMap mmap){
        Task t = taskService.createTaskQuery().taskId(taskid).singleResult();
        String processId = t.getProcessInstanceId();
        ProcessInstance p = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
        if (p != null) {
        	GcFk obj = gcFkService.selectGcFkById(Long.parseLong(p.getBusinessKey().toString()));
        	if(obj.getFap()!=null && !obj.getFap().equals("")){
        		obj.setFap(RuoYiConfig.getOnPath()+obj.getFap());
            }
            GcFkitem gcFkitem = new GcFkitem();
            gcFkitem.setFkId(obj.getId());
            List<GcFkitem> itemlis = gcFkitemService.selectGcFkitemList(gcFkitem);
            obj.setItems(itemlis);
        	mmap.put("obj", obj);
        	
        	GcSupply gcSupply = new GcSupply();
            gcSupply.setDeleteFlag(1);
            List<GcSupply> supplylis = gcSupplyService.selectGcSupplyList(gcSupply);
            mmap.put("supplylis", supplylis);
            
            GcFkfp gcFkfp = new GcFkfp();
            gcFkfp.setDeleteFlag(1);
            gcFkfp.setProjectId(obj.getProjectId());
            gcFkfp.setGcProjectid(obj.getGcProjectid());
            gcFkfp.setCkdw(obj.getCkdw());
            List<GcFkfp> fplis = gcFkfpService.selectGcFkfpList(gcFkfp);
            double fpjine = 0.0;
            for(GcFkfp fp:fplis){
            	fpjine = DecimalCalculateUtil.add(fpjine, Double.parseDouble(fp.getFpjine().toString()));
            }
            mmap.put("fpjine", fpjine);
            
            GcFk gcFk11 = new GcFk();
            gcFk11.setDeleteFlag(1);
            gcFk11.setProjectNo(obj.getProjectNo());
            gcFk11.setXmtype(obj.getXmtype());
            gcFk11.setCkdw(obj.getCkdw());
            List<GcFk> gcfklis = gcFkService.selectGcFkList(gcFk11);
            
            double ljzf = 0.0;
            for(GcFk obj1:gcfklis){
            	ljzf = DecimalCalculateUtil.add(ljzf, Double.parseDouble(obj1.getLjzf().toString()));
            }
            mmap.put("kucljzf", ljzf);
        	
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            mmap.put("taskid", taskid);
            
            //下一级审核人
            mmap.put("approveid", obj.getZjlId());
            mmap.put("approvename", obj.getZjl());
            
          //所属
            SysDept dept = new SysDept();
            dept.setDelFlag("1");
            dept.setParentId(100l);
            List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
            mmap.put("deptlis", deptlis);
        }
        
        return prefix + "/level5check";
    }
    
    /**
     * level1
     * @return
     */
    @GetMapping("/level6")
    public String level6(String taskid, ModelMap mmap){
        Task t = taskService.createTaskQuery().taskId(taskid).singleResult();
        String processId = t.getProcessInstanceId();
        ProcessInstance p = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
        if (p != null) {
        	GcFk obj = gcFkService.selectGcFkById(Long.parseLong(p.getBusinessKey().toString()));
        	if(obj.getFap()!=null && !obj.getFap().equals("")){
        		obj.setFap(RuoYiConfig.getOnPath()+obj.getFap());
            }
            GcFkitem gcFkitem = new GcFkitem();
            gcFkitem.setFkId(obj.getId());
            List<GcFkitem> itemlis = gcFkitemService.selectGcFkitemList(gcFkitem);
            obj.setItems(itemlis);
        	mmap.put("obj", obj);
        	
        	GcSupply gcSupply = new GcSupply();
            gcSupply.setDeleteFlag(1);
            List<GcSupply> supplylis = gcSupplyService.selectGcSupplyList(gcSupply);
            mmap.put("supplylis", supplylis);
            
            GcFkfp gcFkfp = new GcFkfp();
            gcFkfp.setDeleteFlag(1);
            gcFkfp.setProjectId(obj.getProjectId());
            gcFkfp.setGcProjectid(obj.getGcProjectid());
            gcFkfp.setCkdw(obj.getCkdw());
            List<GcFkfp> fplis = gcFkfpService.selectGcFkfpList(gcFkfp);
            double fpjine = 0.0;
            for(GcFkfp fp:fplis){
            	fpjine = DecimalCalculateUtil.add(fpjine, Double.parseDouble(fp.getFpjine().toString()));
            }
            mmap.put("fpjine", fpjine);
            
            GcFk gcFk11 = new GcFk();
            gcFk11.setDeleteFlag(1);
            gcFk11.setProjectNo(obj.getProjectNo());
            gcFk11.setXmtype(obj.getXmtype());
            gcFk11.setCkdw(obj.getCkdw());
            List<GcFk> gcfklis = gcFkService.selectGcFkList(gcFk11);
            
            double ljzf = 0.0;
            for(GcFk obj1:gcfklis){
            	ljzf = DecimalCalculateUtil.add(ljzf, Double.parseDouble(obj1.getLjzf().toString()));
            }
            mmap.put("kucljzf", ljzf);
        	
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            mmap.put("taskid", taskid);
            
            //下一级审核人
            mmap.put("approveid", obj.getCnId());
            mmap.put("approvename", obj.getCn());
            
          //所属
            SysDept dept = new SysDept();
            dept.setDelFlag("1");
            dept.setParentId(100l);
            List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
            mmap.put("deptlis", deptlis);
        }
        
        return prefix + "/level6check";
    }
    
    /**
     * level1
     * @return
     */
    @GetMapping("/level7")
    public String level7(String taskid, ModelMap mmap){
        Task t = taskService.createTaskQuery().taskId(taskid).singleResult();
        String processId = t.getProcessInstanceId();
        ProcessInstance p = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
        if (p != null) {
        	GcFk obj = gcFkService.selectGcFkById(Long.parseLong(p.getBusinessKey().toString()));
        	if(obj.getFap()!=null && !obj.getFap().equals("")){
        		obj.setFap(RuoYiConfig.getOnPath()+obj.getFap());
            }
            GcFkitem gcFkitem = new GcFkitem();
            gcFkitem.setFkId(obj.getId());
            List<GcFkitem> itemlis = gcFkitemService.selectGcFkitemList(gcFkitem);
            obj.setItems(itemlis);
        	mmap.put("obj", obj);
        	
        	GcSupply gcSupply = new GcSupply();
            gcSupply.setDeleteFlag(1);
            List<GcSupply> supplylis = gcSupplyService.selectGcSupplyList(gcSupply);
            mmap.put("supplylis", supplylis);
            
            GcFkfp gcFkfp = new GcFkfp();
            gcFkfp.setDeleteFlag(1);
            gcFkfp.setProjectId(obj.getProjectId());
            gcFkfp.setGcProjectid(obj.getGcProjectid());
            gcFkfp.setCkdw(obj.getCkdw());
            List<GcFkfp> fplis = gcFkfpService.selectGcFkfpList(gcFkfp);
            double fpjine = 0.0;
            for(GcFkfp fp:fplis){
            	fpjine = DecimalCalculateUtil.add(fpjine, Double.parseDouble(fp.getFpjine().toString()));
            }
            mmap.put("fpjine", fpjine);
            
            GcFk gcFk11 = new GcFk();
            gcFk11.setDeleteFlag(1);
            gcFk11.setProjectNo(obj.getProjectNo());
            gcFk11.setXmtype(obj.getXmtype());
            gcFk11.setCkdw(obj.getCkdw());
            List<GcFk> gcfklis = gcFkService.selectGcFkList(gcFk11);
            
            double ljzf = 0.0;
            for(GcFk obj1:gcfklis){
            	ljzf = DecimalCalculateUtil.add(ljzf, Double.parseDouble(obj1.getLjzf().toString()));
            }
            mmap.put("kucljzf", ljzf);
        	
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            mmap.put("taskid", taskid);
            
            //下一级审核人
            List<SjProcessConfig> configlis = returnUser(Long.valueOf(obj.getDeptId().toString()));
            mmap.put("approveid", configlis.get(0).getLevel8id());
            mmap.put("approvename", configlis.get(0).getLevel8name());
            
          //所属
            SysDept dept = new SysDept();
            dept.setDelFlag("1");
            dept.setParentId(100l);
            List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
            mmap.put("deptlis", deptlis);
        }
        
        return prefix + "/level7check";
    }
    
    /**
     * 修改单据
     * @param taskid
     * @param mmap
     * @return
     */
    @GetMapping("/modify")
    public String modify(String taskid, ModelMap mmap){
        Task t = taskService.createTaskQuery().taskId(taskid).singleResult();
        String processId = t.getProcessInstanceId();
        ProcessInstance p = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
        if (p != null) {
        	GcFk obj = gcFkService.selectGcFkById(Long.parseLong(p.getBusinessKey().toString()));
        	if(obj.getFap()!=null && !obj.getFap().equals("")){
        		obj.setFap(RuoYiConfig.getOnPath()+obj.getFap());
            }
            GcFkitem gcFkitem = new GcFkitem();
            gcFkitem.setFkId(obj.getId());
            List<GcFkitem> itemlis = gcFkitemService.selectGcFkitemList(gcFkitem);
            obj.setItems(itemlis);
        	mmap.put("obj", obj);
        	
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            mmap.put("taskid", taskid);
            
            GcSupply gcSupply = new GcSupply();
            gcSupply.setDeleteFlag(1);
            List<GcSupply> supplylis = gcSupplyService.selectGcSupplyList(gcSupply);
            mmap.put("supplylis", supplylis);
            
            GcFkfp gcFkfp = new GcFkfp();
            gcFkfp.setDeleteFlag(1);
            gcFkfp.setProjectId(obj.getProjectId());
            gcFkfp.setGcProjectid(obj.getGcProjectid());
            gcFkfp.setCkdw(obj.getCkdw());
            List<GcFkfp> fplis = gcFkfpService.selectGcFkfpList(gcFkfp);
            double fpjine = 0.0;
            for(GcFkfp fp:fplis){
            	fpjine = DecimalCalculateUtil.add(fpjine, Double.parseDouble(fp.getFpjine().toString()));
            }
            mmap.put("fpjine", fpjine);
            
            GcFk gcFk11 = new GcFk();
            gcFk11.setDeleteFlag(1);
            gcFk11.setProjectNo(obj.getProjectNo());
            gcFk11.setXmtype(obj.getXmtype());
            gcFk11.setCkdw(obj.getCkdw());
            List<GcFk> gcfklis = gcFkService.selectGcFkList(gcFk11);
            
            double ljzf = 0.0;
            for(GcFk obj1:gcfklis){
            	ljzf = DecimalCalculateUtil.add(ljzf, Double.parseDouble(obj1.getLjzf().toString()));
            }
            mmap.put("kucljzf", ljzf);
            
          //所属
            SysDept dept = new SysDept();
            dept.setDelFlag("1");
            dept.setParentId(100l);
            List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
            mmap.put("deptlis", deptlis);
        }
        
        return prefix + "/modifycheck";
    }
}